package com.team.appinfo.controller;

import com.team.appinfo.entity.DevUser;
import com.team.appinfo.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class DevUserController {
    @Autowired
    private DevUserService devUserService;

    @RequestMapping("/login")  //登陆
    public String login(String uresname,String inputCode, String password, HttpSession session, Model model){
        //判断验证码
        //获取生成的验证码:
        String randCode=session.getAttribute("codeValidate").toString();
       if (inputCode.equalsIgnoreCase(randCode)){
           DevUser du=this.devUserService.login(uresname,password);
           if (du==null){
               model.addAttribute("error","登陆错误");
               return "devlogin";
           }else {
               session.setAttribute("du",du);
               session.setMaxInactiveInterval(18000);
               return "developer/main";
           }
       }else {
           model.addAttribute("error","验证码不正确!");
           return "devlogin";   //返回登入页
       }


    }
    @RequestMapping("/logout")
   public String logout(HttpSession session){
        session.removeAttribute("du");
        return "redirect:jsp/devlogin.jsp";
    }

}
